﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Net.Mail;
using System.Net;

namespace SD.Commons
{
    public static class UserCommon
    {
        ///// <summary>
        ///// to ma hoa password
        ///// </summary>
        ///// <param name="stringToHash"></param>
        ///// <returns></returns>

        //public string TaoMangBam(string stringToHash)
        //{
        //    string result = "";
        //    HashAlgorithm Hash = HashAlgorithm.Create("MD5");
        //    byte[] pwordData = Encoding.Default.GetBytes(stringToHash);
        //    //tao ma bam
        //    byte[] hash = Hash.ComputeHash(pwordData);
        //    //hien thi ma bam
        //    // Response.Write(BitConverter.ToString(hash));
        //    result = BitConverter.ToString(hash);
        //    return result;
        //}

        /// <summary>
        /// gui mail cho user khi forget password
        /// </summary>
        /// <param name="subject"></param>
        /// <param name="content"></param>
        /// <param name="diachimail"></param>
        /// <returns></returns>

        public static string SendMail(string subject, string content, string emailAddress)
        {
            try
            {
                MailMessage mailMsg = new MailMessage();
                mailMsg.From = new MailAddress("duongnhattai@gmail.com", "Ban Quản Trị");
                mailMsg.To.Add(emailAddress);
                mailMsg.Subject = subject;
                mailMsg.IsBodyHtml = true;
                mailMsg.Body = content;
                mailMsg.Priority = MailPriority.Normal;
                //phuong thuc dung de gui mail tuong ung voi dia chi may chu
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);//smtp.gmai.com 587 ,465
                //SmtpClient client = new SmtpClient("https://mail.fsoft.com.vn/owa", 80);

                //khi reply lai se vao dia chi nay(dia chi nay lam trung gian de gui toi dia chi txtto.text
                NetworkCredential info = new NetworkCredential("duongnhattai@gmail.com", "luocphen");
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Credentials = info;
                client.EnableSsl = true;
                client.Send(mailMsg);
                return "tc";
            }
            catch
            {
                return "tb";
            }
        }
    }
}
